package com.hspedu.web.fileload;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

@Controller
public class fileUploadHandler {
    @RequestMapping("/upload")
    public String fileUpload(@RequestParam(value = "file")MultipartFile file,
                             HttpServletRequest request,
                             String introduce) throws IOException {
        String filename = file.getOriginalFilename();
        System.out.println("你上传文件名"+filename);
        System.out.println("文件介绍"+introduce);
        String fileFullPath= request.getServletContext().getRealPath("/img/"+filename);
        File saveToFile = new File(fileFullPath);
        file.transferTo(saveToFile);
        return "success";
    }
}
